<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>

<script setup lang="ts">
import { computed, ref, unref } from 'vue';
import { formSchema } from './cash.data';
import { useMessage } from '@/hooks/web/useMessage';
import { getCashApi } from '@/api/core/cash.api';
import { BasicModal, useModalInner } from '@/components/Modal';
import { BasicForm, useForm } from '@/components/Form';

const emit = defineEmits(['success', 'register']);
const { createMessage } = useMessage();
const isUpdate = ref(true);

const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
  labelWidth: 80,
  schemas: formSchema,
  showActionButtonGroup: false,
});

const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  resetFields();
  setModalProps({ confirmLoading: false });
  isUpdate.value = !!data?.isUpdate;
});

/** 标题初始化 */
const getTitle = computed(() => (!unref(isUpdate) ? '新增兑奖' : '编辑兑奖'));

/** 提交按钮 */
</script>
